require("../util.js");
require("../component/components.js");
require("../component/cityChoice.js");
require("../../jsMt/util.js");
var dataInfo=JSON.parse(sessionStorage.getItem("data"));
var vm = new Vue({
    el:"#recruitScreenResult",
    data:{
        loginUid:"",
        type:"",
        name:"",
        pageNumber:"1", //页码
        title:"",//标题
        areaId:"",//地点id
        areaName:"地点",
        salaryId:"",//薪水id
        salaryName:"薪水(元)",
        salaryList:[],
        categoryId:"",//分类id
        recruitList:{},
        recruitList1:[],
        recruitList2:[],//职位列表
        isScreen:"",
        dataInfo:dataInfo,
        chinaList:{
            provinces:[],//省
            cities:[],//市
            areas:[]//县
        },//中国省市列表
        provinceId:"",
        cityId:"",
        citiesList:[],//市列表
        areasList:[],//区列表
        message:"工作地点"
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.title=decodeURI(this.searchObject&&this.searchObject.title);
        this.type=this.searchObject&&this.searchObject.type;
        this.loginUid=this.searchObject&&this.searchObject.uid;
        this.getEnterpriseRecruitList();
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //招聘主页职位列表
        getEnterpriseRecruitList:function(){
            var that=this,url,data;
            if(that.type==1){
                data={
                    categoryId:that.categoryId,
                    pageNumber:that.pageNumber,
                    areaId:that.areaId,
                    title:that.title,
                    salaryId:that.salaryId,
                    loginUid:that.loginUid
                };
                url="/recruit/getEnterpriseRecruitList"
            }else if(that.type==2){
                data={
                    pageNumber:that.pageNumber,
                    loginUid:that.loginUid
                };
                url="/happyi/getUserResumeList"
            }
            console.log(data);
            this.ajax({url:url,data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.recruitList=b.json.data;
                    that.recruitList1=that.recruitList.list;
                    if(that.recruitList.pageNumber>1){
                        if(that.recruitList.list.length>0) {
                            that.recruitList2 = that.recruitList2.concat(b.json.data.list);
                        }
                    }else{
                        that.recruitList2= that.recruitList1;
                    }
                    vm.loadFlag=false;
                    //console.log(that.categorytopList)
                }else{
                    vm.$refs.prompt.toast("获取职位列表失败！")
                }
            });
        },
        getClass:function(type,item){
            console.log(item)
            var that=this;
            if(type==2){ //薪酬
                that.salaryId=item.id;
                that.salaryName=item.value;
            }
            that.getEnterpriseRecruitList();
            that.getIsScreen();
        },
        getIsScreen:function(num){
            var that=this;
            that.isScreen=num;
            if(num==3){
                var arr={};
                that.salaryList=[];
                that.dataInfo.dict.forEach(function(val,key){
                    if(val.type=="hk_recruit_salary"){
                        arr={};
                        arr.id=val.id;
                        arr.value=val.label;
                        that.salaryList.push(arr);
                    }
                });
                console.log(that.salaryList)
            }
        },
        choiceList:function(data){
            console.log(data)
            this.areaId=data.areasId;
            this.areaName=data.areasName;
            this.getEnterpriseRecruitList();
        },
        //下一页
        getNext:function(type,item){
            if(type==1){
                location.href="/happyi/resumePreview?type=2&resumeId="+item.resumeId+"&loginUid="+this.loginUid;
            }else if(type==2){
                location.href="/see/recruitVideo?uid="+this.loginUid+"&recruitId="+item.recruitId;
            }else if(type==3){
                // location.href="/see/companyInfo?uid="+userInfo.id+"&enterpriseId="+item.enterpriseId;
            }
        }
    }
    ,watch:{
        name:function(){
            var that=this;
            console.log(that.name.length);
            if(that.name.length>0){
                that.isHistory=true;
            }else{
                that.isHistory=false;
            }
            that.searchRecruit();
        },
        title:function(){
            var that=this;
            if(!that.title){
                that.getBack();
            }
        }
    }
});